/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cjava.system.bean;

import java.io.IOException;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.servlet.ServletException;
import org.cjava.system.model.SystemUser;
import org.cjava.system.util.faces.FacesUtil;
import org.omnifaces.util.Faces;

/**
 *
 * @author max
 */
@ManagedBean
@SessionScoped
public class IndexUserBean implements Serializable{
    private static final long serialVersionUID = 1L;
    private String userName;
        
    public void menuAdmin() {
        System.out.println("MenuGenerado");
    }
    
    public void menuStudent() {
        
    }
    
    public void menuSistem() {
        
    }
    
    public void menuSecretary() {
        
    }
    
    public void logOut() {
        try {
            Faces.removeSessionAttribute(FacesUtil.ATTRIBUTE_USER);
            Faces.logout();
            Faces.invalidateSession();
            Faces.redirect("login.jsf");
        } catch (ServletException ex) {
            Logger.getLogger(IndexUserBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(IndexUserBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

    public String getUserName() {
        userName = ((SystemUser)Faces.getSessionAttribute(FacesUtil.ATTRIBUTE_USER)).getUserName();
        return userName;
    }
    
    
}
